<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>交大体检系统</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
    body
    {
        background-image: url(images/bg.jpg);
        background-repeat: no-repeat;
        background-size: cover;
        width: 100%;
        height: 100%;
    }
    #container{height:100%;width:100%;}
    input:-webkit-autofill{-webkit-box-shadow:inset 0 0 0 1000px#fff;background-color:transparent}
    .admin-login-background{width:300px;height:300px;position:absolute;left:50%;top:40%;margin-left:-150px;margin-top:-100px}
    .admin-header{text-align:center;margin-bottom:20px;color:#ffffff;font-weight:bold;font-size:40px}
    .admin-input{border-top-style:none;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;height:50px;width:300px;padding-bottom:0px;border-radius:10px 10px 10px 10px;margin-bottom:3pt}
    .admin-input::-webkit-input-placeholder{color: #4b4e8b
    }
    .layui-icon-username{color:#4b4e8b !important}
    .layui-icon-username:hover{color: #9dcec7 !important}
    .layui-icon-password{color: #4b4e8b !important}
    .layui-icon-password:hover{color: #94d2c9 !important}
    .admin-input-username{border-top-style:solid;border-radius:10px 10px 10px 10px;margin-bottom:3pt}
    .admin-input-verify{border-radius:10px 10px 10px 10px;margin-bottom:3pt}
    .admin-button{margin-top:1pt;font-weight:bold;font-size:18px;width:300px;height:50px;border-radius:5px;background-color: #2f3499;border:1px solid #9fa5d8;border-radius:10px 10px 10px 10px;
    }
    .admin-icon{margin-left:260px;margin-top:10px;font-size:30px;}
    i{position:absolute}
    .admin-captcha{position:absolute;margin-left:205px;margin-top:-45px;}
    </style>
</head>
<body>
<div id="container">
    <div></div>
    <div class="admin-login-background">
        <div class="admin-header">
            <span>交大体检系统</span>
        </div>
        <form class="layui-form" action="">
            <div>
                <i class="layui-icon layui-icon-username admin-icon"></i>
                <input type="text" name="username" placeholder="请输入用户名" autocomplete="off"
                       class="layui-input admin-input admin-input-username" value="admin">
            </div>
            <div>
                <i class="layui-icon layui-icon-password admin-icon"></i>
                <input type="password" name="password" placeholder="请输入密码" autocomplete="off"
                       class="layui-input admin-input" value="123456">
            </div>
            <div class="layui-anim layui-anim-scalesmall ">
                <input type="text" name="captcha" id="captcha" placeholder="请输入验证码" autocomplete="off"
                       class="layui-input admin-input admin-input-verify">
                <img class="admin-captcha" width="90" height="40" src="/sys/getVerify">
                <img  onClick="this.src=this.src+'?'+Math.random();" id="img" class="admin-captcha" width="90" height="40" src="/sys/getVerify">
            </div>
            <button class="layui-btn layui-btn-normal layui-btn-fluid admin-button " lay-submit="" lay-filter="login">登 陆</button>
        </form>
    </div>
</div>
</body>
<script src="/layui/layui.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;
        // 进行登录操作
        form.on('submit(login)', function (data) {
            data = data.field;
            console.log(JSON.stringify(data))
            if (data.captcha == '') {
                layer.msg('请输入验证码');
                return false;
            }
            if (data.username == '') {
                layer.msg('用户名不能为空');
                return false;
            }
            if (data.password == '') {
                layer.msg('密码不能为空');
                return false;
            }

            $.post({
                type: 'POST',
                url: 'sys/user/login',
                dataType: "JSON",
                data: JSON.stringify(data),
                contentType: "application/json",
                success: function (res) {
                    if (res.code === 0) {
                        layui.data('LocalData', {
                            key: "access_token",
                            value: res.data.accessToken
                        })
                        layer.msg('登录成功',{time:1000,icon:1
                        },function () {
                            window.location = '/index/home';
                        });
                    } else {
                        layer.msg(res.msg);
                        $("#img").click();
                    }
                }
            })
            return false;
        });
    });
</script>
</html>
